package com.amumu.drama.common.modules.service.impl.sms;

import com.amumu.drama.common.modules.service.ShortMessageService;
import com.amumu.drama.common.modules.service.impl.sms.model.SendSmsRequest;
import com.amumu.drama.common.modules.service.impl.sms.model.SmsResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author robotto
 * @version 1.0
 * @date 2022/7/2 17:03
 **/
public abstract class AbstractCaptchaService implements ShortMessageService {

    protected final Logger logger = LoggerFactory.getLogger(AbstractCaptchaService.class);
    protected static final String REGION_CODE = "+86";
    protected static final String SUCCESS_CODE = "OK";


    protected abstract SmsResponse doSendMessage(SendSmsRequest sendSmsRequest);

    protected abstract SendSmsRequest buildSmsCaptchaRequest(String phoneNo, String params);

    @Override
    public SmsResponse sendSmsCaptcha(String phoneNo, String params) {
        logger.info("sms service phone num: {}, params: {}", phoneNo, params);
        try {
            SendSmsRequest sendSmsRequest = this.buildSmsCaptchaRequest(phoneNo, params);
            SmsResponse smsResponse = this.doSendMessage(sendSmsRequest);

            this.createSmsLog(phoneNo, sendSmsRequest, smsResponse);
            return smsResponse;
        } catch (Exception e) {
            logger.error("{}-{}-sms service error: {}", phoneNo, params, e.getMessage());
            throw e;
        }
    }

    private void createSmsLog(String phoneNo, SendSmsRequest sendSmsRequest, SmsResponse smsResponse) {

    }



}
